<style>
  details details { padding: 1em 0 0 1.5em; }
</style>
<% experiment = @experiment %>
<h1><%= experiment.name %><% unless experiment.active? %> <small class="closed">Completed</small><% end %></h1>
<%# NOTE: The root_path is the Rails's engine root path, not the application's root path (e.g. "/") %>
<p><%= link_to "Back to Experiments", FieldTest.railtie_routes_url_helpers.experiment_path(experiment.id) %></p>

<h2><%= @goal.titleize %></h2>
<% results = experiment.results(goal: @goal) %>

<table>
  <thead>
    <tr>
      <th>Variant</th>
      <th style="width: 20%;">Participants</th>
      <th style="width: 20%;">Conversions</th>
      <th style="width: 20%;">Conversion Rate</th>
      <th style="width: 20%;">Prob Winning</th>
    </tr>
  </thead>
  <tbody>
    <% results.each do |variant, result| %>
      <tr>
        <td>
          <%= variant %>
          <% if variant == experiment.winner %>
            <span class="check">✓</span>
          <% end %>
        </td>
        <td><%= result[:participated] %></td>
        <td><%= result[:converted] %></td>
        <td>
          <% if result[:conversion_rate] %>
            <%= (100.0 * result[:conversion_rate]).round(FieldTest.precision) %>%
          <% else %>
            -
          <% end %>
        </td>
        <td>
          <% if result[:prob_winning] %>
            <% if result[:prob_winning] < 0.01 %>
              &lt; 1%
            <% else %>
              <%= (100.0 * result[:prob_winning]).round(FieldTest.precision) %>%
            <% end %>
          <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
